package com.lapis17.stock.controller;

import com.lapis17.stock.pojo.domain.InnerMarketDomain;
import com.lapis17.stock.pojo.domain.StockBlockDomain;
import com.lapis17.stock.pojo.domain.StockUpdownDomain;
import com.lapis17.stock.service.StockService;
import com.lapis17.stock.vo.resp.PageResult;
import com.lapis17.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 大盘数据相关接口
 */
@Api(value = "/api/quot", tags = {"大盘数据相关接口"})
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;


    /*
    获取大盘数据
     */
    @ApiOperation(value = "获取大盘数据", notes = "获取大盘数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getStockInfo() {
        return stockService.getStockInfo();
    }

    @ApiOperation(value = "板块数据接口", notes = "板块数据接口", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getStockBlock() {
        return stockService.getStockBlock();
    }

    /**
     * 个体数据获取
     *
     * @param page     当前页
     * @param pageSize 每页记录数
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页记录数")
    })
    @ApiOperation(value = "涨幅榜查看更多接口", notes = "", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> stockInfoByPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                            @RequestParam(value = "pageSize", required = false, defaultValue = "20")
                                                                    Integer pageSize) {

        return stockService.stockInfoByPage(page, pageSize);


    }

    /**
     * 涨幅榜前四个信息接口
     *
     * @return
     */

    @ApiOperation(value = "涨幅榜前四个信息接口", notes = "涨幅榜前四个信息接口", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getIncrease() {
        return stockService.getIncrease();
    }


    @ApiOperation(value = "涨停跌停接口", notes = "涨停跌停接口", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String, List>> stockInfoUpDownCount() {

        return stockService.stockInfoUpDownCount();
    }

    /**
     * 股票信息导出
     *
     * @param page                当前页
     * @param pageSize            每页记录数
     * @param httpServletResponse
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页记录数")
    })
    @ApiOperation(value = "股票信息导出", notes = "股票信息导出", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void exportStockUpDownInfo(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                      @RequestParam(value = "pageSize", required = false, defaultValue = "20")
                                              Integer pageSize, HttpServletResponse httpServletResponse) {

        stockService.exportStockUpDownInfo(page
                , pageSize, httpServletResponse);


    }

    /**
     * 统计T日和T-1日的成交量对比
     *
     * @return
     */
    @ApiOperation(value = "统计T日和T-1日的成交量对比", notes = "统计T日和T-1日的成交量对比", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String, List>> getStockComparedTradeAmt() {
        return stockService.getStockComparedTradeAmt();
    }

    /**
     * 统计当前时间下，A股在各个涨跌区间股票的数量
     * @return
     */
    @ApiOperation(value = "统计当前时间下，A股在各个涨跌区间股票的数量", notes = "统计当前时间下，A股在各个涨跌区间股票的数量", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> getStockInfoCount() {
        return stockService.getStockInfoCount();
    }
    }
